var  file = function(path){
	var width = $(window).width();
	var height = $(window).height();
	
	var temp = $("<div id='fd' style='width:"+width+"px;height:"+height+"px;overflow:hidden;position:fixed;top:0px;left:0px;background: white;'></div>");
	var title =$("<div style='width:"+width+"px;height:30px;border-bottom: 1px solid #CAC8C8;line-height:30px;color:#5B5B5B' id=''><span id='path' style='margin-left:20px'>路径</span><span id='files'>文件</span></div>");
	 var top = $("<div style='width:"+width+"px;height:"+(height-70)+"px;overflow: auto;' id='infodiv'></div>");
	 temp.append(title);
	 temp.append(top);
	
	 var btn =$("<div style='width:"+width+"px;height:30px;border-top: 1px solid #CAC8C8;' id='btndiv'></div>");
	temp.append(btn); 
	 var a_css = { "display": "block", "float":"left","font-weight": "700", "height": "30px", "line-height": "30px","width":"60px","text-align":"center", "border": "1px solid #ccc",
		      "text-decoration": "none", "color": "#5B5B5B","margin":"5px 10px 0px 10px"
		    };

		    var $ok = $('<a href="javascript:void(0);">确 定</a>');
		    $ok.css(a_css);
		    btn.append($ok);
		    var re = $('<a href="javascript:void(0);" style="">刷 新</a>');
		    re.css(a_css);
		    btn.append(re);
		    re.click(function(){
		    	getFile(baurl);
		    });
		    
		    var del = $('<a href="javascript:void(0);" style="">删 除</a>');
		    del.css(a_css);
		    btn.append(del);
		    del.click(function(){
		    	var file = $(".fpath:checked");
		    	if ( file.size() == 0){
		    		alert("请选择需要删除的文件!");
		    		return;
		    	}
		    	
		    	Wconfirm("确认删除选中文件,不可恢复!",{
		    		yes:function(){
		    			var path = "";
		    			file.each(function(i){
		    				path+=","+$(this).val();
		    			});
		    			Wloading3("删除中!");
		    			$.ajax({
		    				type:"post",
		    				url:"delfile.action",
		    				data:{path:path},
		    				success:function(data){
		    					if ( data == "true"){
		    						Wtip2("删除成功!",{ok:function(){
		    							getFile(baurl);
		    						}});
		    						return;
		    					}
		    					alert(data);
		    				}
		    				
		    			});
		    		}
		    		
		    	});
		    });
		    
		    var ba = $('<a href="javascript:void(0);" style="">返 回</a>');
		    ba.css(a_css);
		    btn.append(ba);
		    ba.click(function(){
		    	// / model/model_page/
		    	getFile(burl);
		    });
    //发请求.		    
  $("body").append(temp);
  getFile(path);
}
var baurl ;
var burl;
var i = 0;
function getFile( path){
	
	baurl = path;
	Wloading3("正在加载文件..");
	$.ajax({
		type:"post",
		url:"ajaxfile.action",
		data:{path:path},
		success:function(data){
			burl = data.last+"/";
			$("#path").text("当前路径:"+path);
			$("#files").text(",文件总数:"+data.count);
			closeDialog();
			data = data.root;
			if (data.length == 0){
				$("#infodiv").append("无文件");
			}
			$("#infodiv").empty();
			$("input[type='file']").remove();
			$.each(data,function(i,n){
				if (n.name.indexOf(".html") > 0){
					$("#infodiv").append("<div id='file"+i+"' style='height:120px;width:130px;float:left;margin:5px;border:1px solid #E9E5E5'><img width='130' height='100' style='float:left' src='frame/images/"+n.type+".png'/><div style='float:left;text-align:center;height:19px;line-height:19px;width:130px;border-top:1px solid #E9E5E5;color:#636060'><input type='checkbox' style='vertical-align:middle' value='"+path+n.name+"' class='fpath'/><a href='"+path+n.name+"' target='_blank'>"+n.name+"</a></div></div>");
				}else{
					
					$("#infodiv").append("<div id='file"+i+"' style='height:120px;width:130px;float:left;margin:5px;border:1px solid #E9E5E5'><img width='130' height='100' style='float:left' src='frame/images/"+n.type+".png'/><div style='float:left;text-align:center;height:19px;line-height:19px;width:130px;border-top:1px solid #E9E5E5;color:#636060'><input type='checkbox' style='vertical-align:middle' value='"+path+n.name+"' class='fpath'/>"+n.name+"</div></div>");
				}
				
				
				if ( n.type == "dir"){
					$("#file"+i).dblclick(function(){
						burl = path;
						getFile(path+n.name+"/");
					});
				}
			});
			$("#infodiv").append("<div id='upload' style='height:120px;width:130px;float:left;margin:5px;border:1px solid #E9E5E5'><img width='26' height='26' style='float:left;margin:37px 52px' src='frame/images/add.png'/></div>");
			
			while(true){
				if ($("#upload").size() > 0){
					new AjaxUpload('upload', {
						action : 'upload3.action?source='+path,
						name : 'Filedata', 
						autoSubmit:true,
						responseType: "json",
						onChange: function(file, extension){
						
						},
						onSubmit : function(file, ext) {
						
							 Wloading3("正在上传..");
						},
						onComplete : function(file, response) {
							if(response.err){
								alert(response.msg);
							}else{
							 closeDialog();
							 getFile(path);
							}
						}
					});
					break;
				}
				
			}
		
		}
		
	});
	
	
}

